import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

import vuexPersist from "vuex-persist";
export default new Vuex.Store({
  state: {
    celllist: [],
  },
  mutations: {
    add(state, val) {
      //我们在这里接受到的val是传过来的整条数据
      let res = state.celllist.filter((item) => {
        return item.id == val.id;
      });
      if (res.length != 0) {
        alert("不能重复添加");
        return false;
      }
      state.celllist.push(val);
    },
    remove(state, index) {
      state.celllist.splice(index, 1);
    },
  },
  actions: {},
  modules: {},
  plugins: [
    new vuexPersist({
      storage: window.localStorage,
    }).plugin,
  ],
});
